Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
object-keys
Advanced tools
An Object.keys replacement, in case Object.keys is not available. From https://github.com/es-shims/es5-shim
The object-keys npm package is a utility that provides a shim for the Object.keys method, which returns an array of a given object's own enumerable property names. It is particularly useful for environments that do not support the native Object.keys method, such as older versions of JavaScript engines.
Shim for Object.keys
Provides a cross-browser implementation of Object.keys to retrieve the keys of an object.
var keys = require('object-keys');
var obj = { a: 1, b: 2, c: 3 };
console.log(keys(obj)); // ['a', 'b', 'c']
Lodash is a popular utility library that includes a method called _.keys, which is similar to object-keys. It provides a more robust solution for getting the keys of an object, handling edge cases and supporting a wider range of environments, but it is part of a larger library which may be more than needed if only this functionality is required.
Core-js is a modular standard library for JavaScript, which includes polyfills for many ECMAScript features. It offers a polyfill for Object.keys, among many other features. It is more comprehensive than object-keys, but also larger in size, which might not be ideal for projects looking to minimize dependencies.
An Object.keys shim. Invoke its "shim" method to shim Object.keys if it is unavailable.
Most common usage:
var keys = Object.keys || require('object-keys');
var keys = require('object-keys');
var assert = require('assert');
var obj = {
a: true,
b: true,
c: true
};
assert.deepEqual(keys(obj), ['a', 'b', 'c']);
var keys = require('object-keys');
var assert = require('assert');
/* when Object.keys is not present */
delete Object.keys;
var shimmedKeys = keys.shim();
assert.equal(shimmedKeys, keys);
assert.deepEqual(Object.keys(obj), keys(obj));
var keys = require('object-keys');
var assert = require('assert');
/* when Object.keys is present */
var shimmedKeys = keys.shim();
assert.equal(shimmedKeys, Object.keys);
assert.deepEqual(Object.keys(obj), keys(obj));
Implementation taken directly from es5-shim, with modifications, including from lodash.
Simply clone the repo, npm install
, and run npm test
FAQs
An Object.keys replacement, in case Object.keys is not available. From https://github.com/es-shims/es5-shim
We found that object-keys demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.